﻿-- =========================================================================================================
-- Author:		MICHAEL RITACCO
-- Copyright:	2010 MEKHANO GROUP LLC
-- Version:		10/02/2010 1.0
-- =========================================================================================================
CREATE PROCEDURE [flcr].[api_device_dependent_sel_lov]
@DEVICE_DEPENDENT_ID INT = NULL
,@ACTIVE_FLG INT = NULL
,@DEVICE_ID INT = NULL
,@DEPD_DEVICE_ID INT = NULL
,@DEVICE_PROP_TYPE INT = NULL

AS
BEGIN TRY
  
	SELECT	A.[DEVICE_DEPENDENT_ID]
			,A.[DEVICE_ID]
			,A.[DEVICE_ID_DEPD] 
			,A.[DEVICE_PROP_TYPE]
			,B.[DEVICE_PROP_TYPE_NAME]
			,C.[DEVICE_ASSET_NAME] 
			,C.[DEVICE_ASSET_TAG]
			,D.[DEVICE_ASSET_NAME] AS [DEPD_DEVICE_ASSET_NAME]
			,D.[DEVICE_ASSET_TAG]  AS [DEPD_DEVICE_ASSET_TAG]  
	  FROM	[FLCR].[DEVICE_DEPENDENT] A
     INNER JOIN [FLCR].[DEVICE_PROPERTY_TYPE] B
		ON	A.[DEVICE_PROP_TYPE] = B.[DEVICE_PROP_TYPE]
     INNER JOIN [FLCR].[DEVICE] C
		ON	A.[DEVICE_ID] = C.[DEVICE_ID]
     INNER JOIN [FLCR].[DEVICE] D
		ON	A.[DEVICE_ID_DEPD] = D.[DEVICE_ID]
     WHERE	A.[DEVICE_DEPENDENT_ID]  = COALESCE(@DEVICE_DEPENDENT_ID,A.[DEVICE_DEPENDENT_ID])
	  AND	A.[ACTIVE_FLG] = COALESCE(@ACTIVE_FLG,A.[ACTIVE_FLG])
	  AND	A.[DEVICE_ID] = COALESCE(@DEVICE_ID,A.[DEVICE_ID])
	  AND	A.[DEVICE_ID_DEPD] = COALESCE(@DEPD_DEVICE_ID,A.[DEVICE_ID_DEPD])
	  AND	A.[DEVICE_PROP_TYPE] = COALESCE(@DEVICE_PROP_TYPE,A.[DEVICE_PROP_TYPE])

END TRY
BEGIN CATCH
	EXEC [flcr].[utl_getDBError];
END CATCH
